package com.tgu.home_action.dao;

import com.tgu.home_action.pojo.Volunteer;
import com.tgu.home_action.pojo.VolunteerCase;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VolunteerCaseMapper {
    /**
     * 根据caseId和volunteerId查询
     */
    @Select("select * from volunteer_case where case_id=#{caseId} and volunteer_id=#{volunteerId}")
    VolunteerCase getVolunteerCase(VolunteerCase volunteerCase);

    /**
     * 插入
     */
    void insertVolunteerCase(VolunteerCase volunteerCase);

    /**
     * 通过志愿者id查询其参与的正在进行的案件
     */
    List<Integer> getIngCaseIdByVolunteerId(Integer volunteerId);

    /**
     * 通过案件ID查询志愿者
     */
    List<Volunteer> getVolunteerByCaseId(Integer caseId);

    /**
     * 修改志愿者的案件状态
     */
    @Update("update volunteer_case set state=#{state} where volunteer_id=#{volunteerId} and case_id=#{caseId}")
    void updateState(VolunteerCase volunteerCase);

    /**
     * 通过志愿者ID删除
     */
    @Delete("delete from volunteer_case where volunteer_id=#{volunteerId}")
    void deleteByVolunteerId(Integer volunteerId);
}
